package fast.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import fast.calc.Buffs;
import fast.loader.Profession;
import fast.loader.Race;
import fast.loader.TalentDB;
import fast.loader.Weapon;


public class BaseStats extends StatBlock {
	
	private Race race;
	
	private Weapon mh;
	private Weapon oh;
	
	private HashMap<String,Integer> setItemsMap = new HashMap<String,Integer>();
	private Set<String> setItems = new HashSet<String>();
	private List<String> gearBuffs = new ArrayList<String>();
	private HashMap<String,Integer> gearBuffItemLevel = new HashMap<String,Integer>();
	
	private CharacterClass characterClass;
	private Set<String> talents = new HashSet<String>();
	private Set<String> offTalents = new HashSet<String>();
	private Spec spec;
	private Spec offSpec;
	
	private List<Profession> professions = new ArrayList<Profession>();

	private List<String> glyphs = new ArrayList<String>();
	private List<String> offGlyphs = new ArrayList<String>();
	
	private List<Integer> achievements = new ArrayList<Integer>();
	
	private List<String> buffs = new ArrayList<String>();

	public BaseStats(){
		buffs.clear();
		buffs.addAll(Buffs.validBuffs);
	}
	
	public void setMH(Weapon w){
		mh = w;
	}
	
	public void setOH(Weapon w){
		oh = w;
	}
	
	public Weapon getMH(){
		return mh;
	}
	
	public Weapon getOH(){
		return oh;
	}
	
	public void setRace(Race race) {
		this.race = race;
	}
	
	public Race getRace() {
		return race;
	}
	
	public int getNumberOfSetItems(String setname){
		if(!this.setItemsMap.containsKey(setname))
			return 0;
		return this.setItemsMap.get(setname);
	}
		
	public Set<String> getSetItems(){
		return setItems;
	}
	
	public void addSetItem(String setname){
		if(!this.setItemsMap.containsKey(setname))
			   this.setItemsMap.put(setname, 1);
		   else
			   this.setItemsMap.put(setname, setItemsMap.get(setname)+1);
		if(this.setItemsMap.get(setname) >= 2){
			this.setItems.add(setname.toLowerCase()+"_2pc");
		}
		if(this.setItemsMap.get(setname) >= 4){
			this.setItems.add(setname.toLowerCase()+"_4pc");
		}
	}

	public Set<String> getTalents(){
		return talents;
	}
	
	public Set<String> getOffTalents(){
		return offTalents;
	}
	
	public void addGearBuff(String name){
		gearBuffs.add(name);
	}
	
	public List<String> getGearBuffs(){
		return gearBuffs;
	}
	
	public void setGearBuffs(List<String> gearBuffs){
		this.gearBuffs = gearBuffs;
	}
	
	public void addProfession(Profession name){
		professions.add(name);
	}
	public List<Profession> getProfessions(){
		return professions;
	}

	public void addGlyph(String name) {
		glyphs.add(name);
	}
	
	public void addOffGlyph(String name) {
		offGlyphs.add(name);
	}
	
	public void setGlyphs(List<String> g){
		glyphs = g;
	}
	
	public List<String> getGlyphs(){
		return glyphs;
	}
	
	public void setOffGlyphs(List<String> g){
		offGlyphs = g;
	}
	
	public List<String> getOffGlyphs(){
		return offGlyphs;
	}

	public void removeProfession(String prof) {
		professions.remove(prof);
	}

	public void setSpec(Spec s) {
		spec = s;
	}
	
	public void setOffSpec(Spec s) {
		offSpec = s;
	}

	public Spec getSpec() {
		return spec;
	}
	
	public Spec getOffSpec() {
		return offSpec;
	}

	public void removeGlyph(String name) {
		glyphs.remove(name);		
	}

	public void setProfessions(List<Profession> selectedProfessions) {
		professions = selectedProfessions;
	}

	public void setTalents(String string) {
		TalentDB talentDB = new TalentDB(characterClass);
		for(int i = 0;i < string.length();i++){
			if(string.charAt(i) == '.')
				continue;
			int t = Integer.parseInt(String.valueOf(string.charAt(i)));
			talents.add(talentDB.get(i,t));
		}
	}
	
	public void setOffTalents(String string) {
		TalentDB talentDB = new TalentDB(characterClass);
		for(int i = 0;i < string.length();i++){
			if(string.charAt(i) == '.')
				continue;
			int t = Integer.parseInt(String.valueOf(string.charAt(i)));
			offTalents.add(talentDB.get(i,t));
		}
	}

	public void setTalents(Set<String> talentTree) {
		talents.clear();
		talents.addAll(talentTree);
	}

	public void setOffTalents(Set<String> talentTree) {
		offTalents.clear();
		offTalents.addAll(talentTree);		
	}

	public CharacterClass getCharacterClass() {
		return characterClass;
	}

	public void setCharacterClass(CharacterClass cc) {
		characterClass = cc;
	}

	public void addGearBuffItemLevel(String gearBuff, int itemLevel) {
		gearBuffItemLevel.put(gearBuff,itemLevel);		
	}
	
	public HashMap<String,Integer> getGearBuffItemLevel(){
		return gearBuffItemLevel;
	}

	public List<Integer> getAchievements() {
		return achievements;
	}

	public void setAchievements(List<Integer> achievements) {
		this.achievements = achievements;
	}
	
	public void addBuff(String name) {
		buffs.add(name);
	}
	
	public void removeBuff(String name) {
		buffs.remove(name);		
	}
	
	public List<String> getBuffs(){
		return buffs;
	}

	public void setBuffs(List<String> buffs) {
		this.buffs = buffs;		
	}
}
